package com.neusoft.neuiotms.dcom.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.InspectionRuleDTO;
import com.neusoft.neuiotms.dcom.service.InspectionRuleService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "巡检规则")
@RestController
@RequestMapping(value = "/api/w/inspection/rule")
public class InspectionRuleController {
    @Autowired
    private InspectionRuleService ruleService;

    @ApiOperation("查询所有巡检规则")
    @GetMapping
    public ResultListDTO<InspectionRuleDTO> index(final Searchable searchable, final UserBean user) {
        return ResultListDTO.success(this.ruleService.index(searchable, user));
    }

    @ApiOperation("分页查询巡检规则")
    @GetMapping("/p")
    public PageResultDTO<InspectionRuleDTO> page(final Searchable searchable, final Pageable pageable,
            final UserBean user) {
        return PageResultDTO.success(this.ruleService.page(searchable, pageable, user));
    }

    @ApiOperation("新增巡检规则")
    @PostMapping
    public ResultDTO<InspectionRuleDTO> create(@RequestBody final InspectionRuleDTO dto, final UserBean user) {
        return ResultDTO.success(this.ruleService.create(dto, user));
    }

    @ApiOperation("更新巡检规则")
    @PutMapping("/{id}")
    public ResultDTO<InspectionRuleDTO> update(@PathVariable final Long id, @RequestBody final InspectionRuleDTO dto,
            final UserBean user) {
        return ResultDTO.success(this.ruleService.update(id, dto, user));
    }

    @ApiOperation("查看巡检规则")
    @GetMapping("/{id}")
    public ResultDTO<InspectionRuleDTO> details(@PathVariable final Long id) {
        return ResultDTO.success(this.ruleService.detail(id));
    }

    @ApiOperation("删除巡检规则")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.ruleService.delete(id);
        return ResultDTO.success();
    }

    @ApiOperation("启用/停用")
    @PutMapping("/update/status/{id}/{status}")
    public ResultDTO<Void> updateStatus(@PathVariable final Long id, @PathVariable final String status) {
        this.ruleService.updateStatus(id, status);
        return ResultDTO.success();
    }

}
